<template>
  <el-dialog title="更新质控点状态" :close-on-click-modal="false" :visible.sync="dialogParams.visible" width="400px">
    <el-form ref="formData" :rules="rules" :model="formData" label-width="100px">
      <el-form-item label="手工维护值" prop="val">
        <el-input type="text" placeholder="请输入值" v-model.trim="formData.val"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="close('formData')">关 闭</el-button>
      <el-button type="primary" @click="submit('formData')">保 存</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { updateHandworkMaintainValue } from '@/api/target'

export default {
  name: 'updateVal',
  props: {
    dialogParams: {
      type: Object
    }
  },
  data() {
    return {
      formData: {
        val: ''
      },
      rules: {
        val: [{ required: true, message: '请输入当前值', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.formData.val = this.dialogParams.currentValue
  },
  methods: {
    submit(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          const params = {
            id: this.dialogParams.id,
            targetStandardId: this.dialogParams.targetStandardId,
            handworkMaintainValue: this.formData.val
          }
          updateHandworkMaintainValue(params)
            .then(res => {
              this.$message.success('更新成功！')
              this.dialogParams.visible = false
              this.$emit('getList')
            })
            .catch(() => {})
        } else {
          return false
        }
      })
    },
    // 关闭
    close(formName) {
      this.$refs[formName].resetFields()
      this.dialogParams.visible = false
    }
  }
}
</script>

<style scoped>
</style>
